//
//  CDRefreshView.swift
//  XLWB
//
//  Created by MacBook on 16/7/8.
//  Copyright © 2016年 MacBook. All rights reserved.
//

import UIKit

class CDRefreshView: UIView {

    //刷新状态
    var refreshState: CDRefreshState = .Normal {
    
        didSet {
        
            switch refreshState {
            case .Normal:
                //恢复状态
                tipIcon.isHidden = false
                indicator.stopAnimating()
                tipLabel.text = "继续使劲拉"
                
                UIView.animate(withDuration: 0.25) {
                    self.tipIcon.transform = CGAffineTransform.identity
                }
            case .Pulling:
                tipLabel.text = "放手就刷新"
                
                UIView.animate(withDuration: 0.25) {
                    self.tipIcon.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI + 0.001))
                }
            case .WillRefresh:
                tipLabel.text = "正在刷新中"
            
                //隐藏箭头
                tipIcon.isHidden = true
                //显示菊花
                indicator.startAnimating()
            }
        
        }
    }
    
    @IBOutlet weak var tipIcon: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!

    @IBOutlet weak var indicator: UIActivityIndicatorView!
    
    class func refreshView() -> CDRefreshView {
    
        let nib = UINib(nibName: "CDHumanRefreshView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil)[0] as! CDRefreshView
    
    }

}
